<?php
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');#加载全站初始化配置文件
require_once (dirname(__FILE__) .'/includes/Response.php');#json生成类

if (($_REQUEST['act']=='timer_shaft')) {

//    $_POST['user_id'] = isset($_POST['user_id']) ? trim($_POST['user_id']) : '';
    $_POST['user_id'] = 1;
    if (!empty($_POST['user_id'])) {
        $sql = "SELECT user_name,user_sex,user_pic" .
            " FROM " . $ecs->table('user') .
            " WHERE  user_id = '" . $_POST['user_id'] . "' ";
        $row1 = $db->getRow($sql);//查询基本信息顶端的用户名，头像，性别
        $sql = "SELECT activity_id" .
            " FROM " . $ecs->table('user_activity') .
            " WHERE  user_id = '" . $_POST['user_id'] . "' ";
        $activity_id = $db->getAll($sql);//查询活动id
        foreach ($activity_id as $key=>$value) {
            $sql = "SELECT activity_name,activity_cover,activity_re_time,activity_address,fab_num,activity_describe" .
                " FROM " . $ecs->table('activity') .
                " WHERE  activity_id = '" . $value['activity_id'] . "' ";//查询活动名称，封面，发布时间，地址，点赞数，活动描述
            $row2 = $db->getRow($sql);

            $sql = "SELECT ecs_user.user_name,ecs_user.user_pic,ecs_user.user_id FROM " . $ecs->table('user_activity') . "LEFT JOIN " . $ecs->table('user') . "ON ecs_user.user_id = ecs_user_activity.user_id" . " WHERE ecs_user_activity.activity_id ='" . $value['activity_id'] . "'";
            $row3 = $db->getAll($sql);//查询活动参与者用户名，头像，ID
            $row4 = count($row3);//计算参与者数量
            $now_time = strtotime(date("Y-m-d H:i:s"));//当前时间
            $re_time = strtotime($row2['activity_re_time']);//活动发布时间
            $time = $now_time - $re_time;//计算时间差

            $row[] = array(
                'top_information' => $row1,
                'middle_information' => $row2,
                'time_difference' => $time,
                'member' => $row3,
                'member_num' => $row4
            );

        }

        return Response::json(200, "查询数据成功", $row);
    } else {
        return Response::json(450, "参与者与活动不匹配", $id);


    }


}

/**
 * Created by PhpStorm.
 * User: tuhao
 * Date: 2016/11/8
 * Time: 15:23
 */